<?php
Prado::using('Application.common.common');
class ManageBanners extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		if (!$this->IsPostBack)
		{
			$this->Master->pageHead->Title = "Admin | Manage Banners";
			$this->AdminMenu->lnkManageBanner->CssClass = "active";
			
			$this->populateBanners();
			
			if ($this->Request->contains('m')) {
				$this->Notice->Type = UserNoticeType::NoticeAdmin;
				if ($this->Request['m'] == 'db')	
					$this->Notice->Text = $this->Application->getModule('message')->translate('DELETE_SUCCESS','Banner','');				
			}	
		}
	}
	
	protected function populateBanners()
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->Condition = "status >= 1";				
		$criteria->OrdersBy["banner_name"] = "asc";							
		$activeRecord = Prado::createComponent("BannerRecord");
		$limit = null;
		$offset = null;
		$criteria->Limit = $limit;
		$criteria->Offset = $offset;
		$items = $activeRecord->finder()->findAll($criteria);
		$this->ItemList_Request->DataSource = $items;
		$this->ItemList_Request->dataBind();
		$this->lblTotal->Text="Banner (" . count($items) . ")";		
		if (count($items) <= 0)
		{
			$this->lblTotal->Text="There is no banner.";
			$this->lblTotal->Style="text-transform:lower; margin-left:40px;";
		}
	}
	
	protected function list_ItemCreated($sender, $param)
	{
		if ($param->Item->ItemType == "Item" || $param->Item->ItemType == "AlternatingItem")
		{
			if ($param->Item->Data)
			{				
				$param->Item->colImg->imgBannerPhoto->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/photos/banner/slideshow/".$param->Item->Data->BannerPhoto;	
			}
		}
	}	
	
	protected function list_ItemCommand($sender, $param)
	{
		switch($param->CommandName)
		{
			case "delete":			
				$bannerRecord = BannerRecord::finder()->findByPk($param->Item->colButton->txtBannerID->Value);
				$bannerRecord->Status = "-1";
				$bannerRecord->ModifyBy = $this->Application->User->ID;
				$bannerRecord->ModifyDate = time();
				$bannerRecord->save();	
				$this->Response->redirect($this->Service->ConstructUrl('admin.ManageBanners', array('m'=>'db')));				
				break;		
			default:
				break;
		}
	}
}

?>